package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.pojo.Good;
import com.chixing.service.RedisLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 点赞业务。
 */
@RestController
public class PraiseController {
  @Autowired
  private RedisLikeService redisLikeService;

  @PostMapping("/praise/save")
  public String save2redis(Good good,  Integer praiseCount, HttpSession session) {
    Customer loginCustomer = (Customer)session.getAttribute("loginCustomer");
    System.out.println("点赞的状态--------" + good.getGoodStatus());
    System.out.println("点赞数量----------" + praiseCount);
    System.out.println(loginCustomer.getCustumerId());
    //设置点赞信息中的用户id
    good.setCustomerId(loginCustomer.getCustumerId());

    redisLikeService.saveLike2Redis(good,praiseCount);

    return "save praise success";
  }

  @PostMapping("/praise/cancle")
  public String cancle2redis(Good good, Integer praiseCount , HttpSession session) {
    Customer loginCustomer = (Customer)session.getAttribute("loginCustomer");

    System.out.println("点赞的状态--------" + good.getGoodStatus());
    System.out.println("点赞数量----------" + praiseCount);

    good.setCustomerId(loginCustomer.getCustumerId());

    redisLikeService.cancleLike2Redis(good,praiseCount);

    return "cancle praise success";
  }
}
